package com.gitee.wsl.struct.either.ext

import arrow.core.Either
import arrow.core.Option
import arrow.core.Some
import arrow.core.right



inline fun <E, A, B> Either<E, A>.traverse(transform: (value: A) -> Iterable<B>): List<Either<E, B>> =
    when (this) {
        is Either.Left -> listOf(this)
        is Either.Right -> transform(value).map { it.right() }
    }

inline fun <E, A, B> Either<E, A>.traverse(transform: (value: A) -> Option<B>): Option<Either<E, B>> =
    when (this) {
        is Either.Left -> Some(this)
        is Either.Right -> transform(value).map { it.right() }
    }